package cn.edu.gzist.chapter03.web.config;

import cn.edu.gzist.chapter03.web.FirstFilter;
import cn.edu.gzist.chapter03.web.FirstListener;
import cn.edu.gzist.chapter03.web.FirstServlet;
import org.springframework.boot.web.servlet.FilterRegistration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;


// 第二种方式 RegistrationBean方式注册
//@Configuration
public class RegistionConfig {

    @Bean
    public ServletRegistrationBean<FirstServlet> firstServlet() {
        return new ServletRegistrationBean<> (new FirstServlet(),"/h1");
    }

    @Bean("firstFilter2")
    public FilterRegistrationBean<FirstFilter> firstFilter() {
        FilterRegistrationBean<FirstFilter> filterRegistrationBean =
                new  FilterRegistrationBean<>(new  FirstFilter());
        filterRegistrationBean.setUrlPatterns(List.of("/h1"));
        return  filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean<FirstListener> servletListenerRegistrationBean(){
        return new ServletListenerRegistrationBean<>(new FirstListener());
    }
}
